/*
 * Copyright (c) 2003, 2004 Ulrich Hilger, http://dev.uhilger.de, all rights reserved.
 *
 * Published under the terms and conditions of the Apache License 2.0,
 * see http://www.apache.org/licenses/LICENSE-2.0
 */

package de.uhilger.app;

import java.util.logging.*;
import java.text.DateFormat;
import java.util.Locale;
import java.util.Date;

/**
 * format log messages for output to a stream
 *
 * @author Ulrich Hilger, <a href="http://dev.uhilger.de" target="_blank">http://dev.uhilger.de</a>
 * @author Published under the terms and conditions of
 * the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License 2.0</a>
 *
 * @version 2, February 12, 2004
 */

public class StreamLogFormatter extends Formatter {

  /**
   * constructor
   */
  public StreamLogFormatter() {
    lineSeparator = System.getProperty("line.separator"); // (String) java.security.AccessController.doPrivileged(
           // new sun.security.action.GetPropertyAction("line.separator"));
  }

  /**
   * format a log record
   * @param record LogRecord the record to format
   * @return String the formatted log record
   */
  public String format(LogRecord record) {
    StringBuffer buf = new StringBuffer();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.getDefault());
    buf.append(df.format(new Date(record.getMillis())));
    buf.append(" ");
    buf.append(record.getSourceClassName());
    buf.append(": ");
    buf.append(record.getMessage());
    buf.append(lineSeparator);
    return buf.toString();
  }

  /** holds the system dependent line separator */
  private String lineSeparator;

  /** indent space */
  //private static final String indent = "  ";
}

